//排片前台service
export default {
  updateSeating:(parameter,_id) => 
  new Promise(resolve => {
    $.ajax({
      url: `/api/seating/${_id}`,
      type: 'PATCH',
      data: parameter,
      success: data => {resolve(data)}
    });
  }),
  addSeating: (parameter) => {
    return new Promise(resolve => {
       $.ajax({
         url: '/api/schedules/addSeating',
         type: 'POST',
         data: {objData:JSON.stringify(parameter)},
         success: data => resolve(data)
       });
     })
   },
  //===============================================
      getSeatByTheaterId:(_id) =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/getSeats',
          type: 'GET',
          data:{theaterId:_id},
          success: data =>resolve(data)
        });
      }),
      getSeatBySchedules:(_id) =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/getSeating',
          type: 'GET',
          data:{scheduleId:_id},
          success: data =>resolve(data)
        });
      }),

      //===================================================
      getById: (listname,_id="") =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/getById',
          type: 'GET',
          data:{listname,_id},
          success: data => {
            
           return resolve(data)}
        });
      }),
     //获取排片数据库所有数据
     getSchedules: (_id) =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/getSchedules',
          type: 'GET',
          success: data => resolve(data)
        });
      }),
      //更新服务器数据
      update: (parameter,_id) => 
        new Promise(resolve => {
          $.ajax({
            url: `/api/schedules/${_id}`,
            type: 'PATCH',
            data: parameter,
            success: data => {resolve(data)}
          });
        })
      ,
      // 获取电影
      getMovies: () =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/getmovies',
          type: 'GET',
          success: data => resolve(data)
        });
      }),
      //获取影院
      getCinems: () =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/getcinems',
          type: 'GET',
          success: data => resolve(data)
        });
      }),
      //获取影厅
      getTheaters: (cinemasId) =>
      new Promise(resolve => {
        $.ajax({
          url: '/api/schedules/gettheaters',
          type: 'GET',
          data:{_id:cinemasId},
          success: data => resolve(data)
        });
      }),
      //增加排片
    add: (parameter) => {
       return new Promise(resolve => {
          $.ajax({
            url: '/api/schedules/addschedules',
            type: 'POST',
            data: {objData:JSON.stringify(parameter)},
            success: data => resolve(data)
          });
        })
      },
    delete: (removeSchedules) => {
        new Promise(resolve => {
          $.ajax({
            url: `/api/schedules/${removeSchedules._id}`,
            type: 'DELETE',
            success: data => resolve(data)
          });
        })
      },
    setSchedulesData:(storageNmae,Schedules)=>window.localStorage[storageNmae]=JSON.stringify(Schedules),
    getSchedulesData:(storageNmae)=>JSON.parse(window.localStorage[storageNmae])
}